package wc.assignmentPhrase;

import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

public class SimpleAssignment extends AssignmentPhrase {

	@Override
	@SuppressWarnings("unchecked")
	public void createOrderPhrase(HashMap<Entry<String, String>, Integer> _phrases) {
		List<Map.Entry<Map.Entry<String, String>, Integer>> simpleOrderList = (List<Map.Entry<Map.Entry<String, String>, Integer>>) _phrases.entrySet();
        Collections.sort(simpleOrderList, new Comparator<Object>() {
            public int compare(Object o, Object o1) {
				Map.Entry<Map.Entry<String, String>, Float> e1 = (Entry<Entry<String, String>, Float>)o;
				Map.Entry<Map.Entry<String, String>, Float> e2 = (Entry<Entry<String, String>, Float>)o1;
                Float first = (Float)e1.getValue();
                Float second = (Float)e2.getValue();
                if(first > second) {
                	return -1;
                } else if(first < second) {
                	return 1;
                } else {
                	Map.Entry<String, String> key1 = e1.getKey();
                	Map.Entry<String, String> key2 = e2.getKey();
                	return -key1.getKey().toLowerCase().compareTo(key2.getKey().toLowerCase());
                }
            }
        });
        
        for(Map.Entry<Map.Entry<String, String>, Integer> item : simpleOrderList) {
        	addPhrase(item.getKey().getKey(), item.getKey().getValue());
        }
	}

}
